/*
 * 
 */
package ch.gje.playios.communication;

import ch.gje.playios.server.HTTPConnection;

/**
 * Represents a client on the computer
 *
 * @author jannis <jannis@gje.ch
 */
public class ComputerClient extends WebSocketClient {

    /**
     * Constructor
     *
     * @param connection the HTTP connection
     */
    public ComputerClient(HTTPConnection connection) {
        super(connection);
        addToPairingList();
    }

    private void addToPairingList() {
        String pairingNumber = Integer.toString(WebSocketPairer.addUnpairedClient(this));
        while(pairingNumber.length() < 4) {
            pairingNumber = '0' + pairingNumber;
        }
        sendCommand("PairingNumber", pairingNumber);
    }

    @Override
    public void onPaired() {
        sendCommand("Paired");
    }

    @Override
    public void onUnpaired() {
        sendCommand("Unpaired");
        addToPairingList();
    }

    @Override
    public void onReceive(String message) {
        if (partner != null) {
            partner.send(message);
        }
    }
}
